Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Use textContent to retrieve text of nodes. #216

Closed
wants to merge 1 commit into from
Closed

Use textContent to retrieve text of nodes. #216

wants to merge 1 commit into from

Conversation

tristandunn
Copy link
Contributor

I ran into issues checking for text within a node, similar to #195. I'm setting the width and height on html and body to 100% and hiding overflow on body. The text was within an absolute positioned container spanning the height of the page. When overflow was set to auto or hidden on the container the text would no longer be found.

I was unable to recreate the issue even with the full HTML and CSS from my application. To avoid spending all weekend trying to recreate it in a test case I verified the textContent change works by removing the line in the original fix and by using it in my application.

There are some differences between innerText and textContent, best explained by MDN:

Internet Explorer introduced element.innerText. The intention is pretty much the same with a couple of differences:

  • Note that while textContent gets the content of all elements, including script and style elements, the mostly equivalent IE-specific property, innerText, does not.
  • innerText is also aware of style and will not return the text of hidden elements, whereas textContent will.
  • As innerText is aware of CSS styling, it will trigger a reflow, whereas textContent will not.

The one difference I can see possibly being an issue is the fact that textContent will return the text of hidden elements. There's currently no test for it though, so perhaps it is not an issue.

@duelinmarkers
Copy link

Returning the text of hidden elements (as well as script elements) would be a problem for me (and, I suspect, many other users).

@tristandunn tristandunn closed this Dec 5, 2011
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants